/**
 * @file       Context.h
 * @brief      To support the panel switch
 * @author     Huabo Zheng
 * @date       Jan 20, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#ifndef CONTEXT_H_
#define CONTEXT_H_

#include "Object.h"
#include <list>
#include "SafeSingleton.h"
#include "Mutex.h"

namespace NS_LCD_AFW
{
class CPanel;

/**
 *@class  CContext
 *@brief  To support the panel switch
 */
class CContext: public NS_LCD_AFW::CObject
{
public:

	/**
	 *@brief Constructor
	 */
	CContext();

	/**
	*@brief DeConstructor
	*/
	virtual ~CContext();

	/**
	 *@brief  Add a Panel object to context
	 *@details     Add a Panel object to context,and it is a thread-safe operation
	 *@param[in]  pPanel A pointer to a CPanel object
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note
	 *@attention
	 *@see getActivePanel
	 *@see remove
	*/
	void add(CPanel *pPanel);

	/**
	 *@brief  Get the ActivePanel from context
	 *@details    Get the ActivePanel from context,the  panel thar is joined in last is the active panel. It is a thread-safe operation
	 *@exception none
	 *@retval    CPanel *
	 *@return    A pointer to a CPanel object
	 *@note
	 *@attention
	 *@see getActivePanel
	 *@see remove
	*/
	CPanel * getActivePanel() const;

	/**
	 *@brief  Remove a Panel object from context
	 *@details     Remove a Panel object from context,and it is a thread-safe operation
	 *@param[in]  pPanel A pointer to a CPanel object which you want to remove
	 *@exception none
	 *@retval    void
	 *@return    none
	 *@note
	 *@attention The panel was just removed from the context,and the context  would not  be destroy it.So caller is  responsible for destroy destroying
	 *@see getActivePanel
	 *@see add
	*/
	void remove(CPanel *pPanel);
private:

	/**
	 *@typedef std::list<CPanel *> CPanelPtrList;
	 */
	typedef std::list<CPanel *> CPanelPtrList;

	CPanelPtrList m_panelPtrList;

private:
	static CMutex m_sMutex;

private:
	DISABLE_COPY_CONSTRUCTOR_AND_ASSIGN_REFERENCE(CContext);
};

/**
 *@def  AfwGetContext()
 *@brief Get the Application context object instance
 */
#define AfwGetContext()         (&(CSafeSingleton<CContext>::getInstance()))

} /* namespace NS_LCD_AFW */
#endif /* CONTEXT_H_ */
